<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="中文名称" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="中文名称-图谱" prop="chineseNameKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.chineseNameKg"-->
<!--          placeholder="请输入中文名称-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="英文名称" prop="englishName">
        <el-input
          v-model="queryParams.englishName"
          placeholder="请输入英文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="英文名称-图谱" prop="englishNameKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.englishNameKg"-->
<!--          placeholder="请输入英文名称-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="发动方" prop="initiator">-->
<!--        <el-input-->
<!--          v-model="queryParams.initiator"-->
<!--          placeholder="请输入发动方"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="攻击目标" prop="target">-->
<!--        <el-input-->
<!--          v-model="queryParams.target"-->
<!--          placeholder="请输入攻击目标"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="攻击目标-图谱" prop="targetKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.targetKg"-->
<!--          placeholder="请输入攻击目标-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="起始时间" prop="startTime">-->
<!--        <el-input-->
<!--          v-model="queryParams.startTime"-->
<!--          placeholder="请输入起始时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="起始时间-图谱" prop="startTimeKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.startTimeKg"-->
<!--          placeholder="请输入起始时间-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="结束时间" prop="endTime">-->
<!--        <el-input-->
<!--          v-model="queryParams.endTime"-->
<!--          placeholder="请输入结束时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="结束时间-图谱" prop="endTimeKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.endTimeKg"-->
<!--          placeholder="请输入结束时间-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="作战目的" prop="objective">-->
<!--        <el-input-->
<!--          v-model="queryParams.objective"-->
<!--          placeholder="请输入作战目的"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所属行业" prop="industry">-->
<!--        <el-input-->
<!--          v-model="queryParams.industry"-->
<!--          placeholder="请输入所属行业"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所属行业-图谱" prop="industryKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.industryKg"-->
<!--          placeholder="请输入所属行业-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="攻击对象" prop="objectOfAttack">-->
<!--        <el-input-->
<!--          v-model="queryParams.objectOfAttack"-->
<!--          placeholder="请输入攻击对象"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="作战效果" prop="effect">-->
<!--        <el-input-->
<!--          v-model="queryParams.effect"-->
<!--          placeholder="请输入作战效果"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="战例关键词" prop="caseKeywords">-->
<!--        <el-input-->
<!--          v-model="queryParams.caseKeywords"-->
<!--          placeholder="请输入战例关键词"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:examplewar:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:examplewar:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:examplewar:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="examplewarList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键ID，自动递增" align="center" prop="id" />-->
      <el-table-column label="中文名称" show-overflow-tooltip     align="center" prop="chineseName" />
      <el-table-column label="中文名称-图谱" show-overflow-tooltip      align="center" prop="chineseNameKg" />
      <el-table-column label="英文名称" show-overflow-tooltip      align="center" prop="englishName" />
      <el-table-column label="英文名称-图谱" show-overflow-tooltip      align="center" prop="englishNameKg" />
      <el-table-column label="发动方"  show-overflow-tooltip     align="center" prop="initiator" />
      <el-table-column label="攻击目标"  show-overflow-tooltip     align="center" prop="target" />
      <el-table-column label="攻击目标-图谱" show-overflow-tooltip      align="center" prop="targetKg" />
      <el-table-column label="起始时间"  show-overflow-tooltip     align="center" prop="startTime" />
      <el-table-column label="起始时间-图谱" show-overflow-tooltip      align="center" prop="startTimeKg" />
      <el-table-column label="结束时间"  show-overflow-tooltip     align="center" prop="endTime" />
      <el-table-column label="结束时间-图谱"  show-overflow-tooltip     align="center" prop="endTimeKg" />
      <el-table-column label="作战目的"  show-overflow-tooltip     align="center" prop="objective" />
      <el-table-column label="所属行业" show-overflow-tooltip      align="center" prop="industry" />
      <el-table-column label="所属行业-图谱"  show-overflow-tooltip     align="center" prop="industryKg" />
      <el-table-column label="攻击对象"  show-overflow-tooltip     align="center" prop="objectOfAttack" />
      <el-table-column label="作战内容"  show-overflow-tooltip     align="center" prop="content" />
      <el-table-column label="作战工具/武器"  show-overflow-tooltip     align="center" prop="weaponTool" />
      <el-table-column label="作战工具/武器-图谱"  show-overflow-tooltip     align="center" prop="weaponToolKg" />
      <el-table-column label="作战效果"  show-overflow-tooltip     align="center" prop="effect" />
      <el-table-column label="相关报道"  show-overflow-tooltip     align="center" prop="keywords" />
      <el-table-column label="战例关键词"  show-overflow-tooltip     align="center" prop="caseKeywords" />
<!--      <el-table-column label="${comment}" align="center" prop="allInfo" />-->
      <el-table-column label="操作"  fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:examplewar:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:examplewar:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改战例数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="中文名称" prop="chineseName">
          <el-input v-model="form.chineseName" placeholder="请输入中文名称" />
        </el-form-item>
        <el-form-item label="中文名称-图谱" prop="chineseNameKg">
          <el-input v-model="form.chineseNameKg" placeholder="请输入中文名称-图谱" />
        </el-form-item>
        <el-form-item label="英文名称" prop="englishName">
          <el-input v-model="form.englishName" placeholder="请输入英文名称" />
        </el-form-item>
        <el-form-item label="英文名称-图谱" prop="englishNameKg">
          <el-input v-model="form.englishNameKg" placeholder="请输入英文名称-图谱" />
        </el-form-item>
        <el-form-item label="发动方" prop="initiator">
          <el-input v-model="form.initiator" placeholder="请输入发动方" />
        </el-form-item>
        <el-form-item label="攻击目标" prop="target">
          <el-input v-model="form.target" placeholder="请输入攻击目标" />
        </el-form-item>
        <el-form-item label="攻击目标-图谱" prop="targetKg">
          <el-input v-model="form.targetKg" placeholder="请输入攻击目标-图谱" />
        </el-form-item>
        <el-form-item label="起始时间" prop="startTime">
          <el-input v-model="form.startTime" placeholder="请输入起始时间" />
        </el-form-item>
        <el-form-item label="起始时间-图谱" prop="startTimeKg">
          <el-input v-model="form.startTimeKg" placeholder="请输入起始时间-图谱" />
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-input v-model="form.endTime" placeholder="请输入结束时间" />
        </el-form-item>
        <el-form-item label="结束时间-图谱" prop="endTimeKg">
          <el-input v-model="form.endTimeKg" placeholder="请输入结束时间-图谱" />
        </el-form-item>
        <el-form-item label="作战目的" prop="objective">
          <el-input v-model="form.objective" placeholder="请输入作战目的" />
        </el-form-item>
        <el-form-item label="所属行业" prop="industry">
          <el-input v-model="form.industry" placeholder="请输入所属行业" />
        </el-form-item>
        <el-form-item label="所属行业-图谱" prop="industryKg">
          <el-input v-model="form.industryKg" placeholder="请输入所属行业-图谱" />
        </el-form-item>
        <el-form-item label="攻击对象" prop="objectOfAttack">
          <el-input v-model="form.objectOfAttack" placeholder="请输入攻击对象" />
        </el-form-item>
        <el-form-item label="作战内容" prop="content">
          <el-input    v-model="form.content" type="textarea"  />
        </el-form-item>
        <el-form-item label="作战工具/武器" prop="weaponTool">
          <el-input v-model="form.weaponTool" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="作战工具/武器-图谱" prop="weaponToolKg">
          <el-input v-model="form.weaponToolKg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="作战效果" prop="effect">
          <el-input v-model="form.effect" placeholder="请输入作战效果" />
        </el-form-item>
        <el-form-item label="相关报道" prop="keywords">
          <el-input v-model="form.keywords" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="战例关键词" prop="caseKeywords">
          <el-input v-model="form.caseKeywords" placeholder="请输入战例关键词" />
        </el-form-item>
<!--        <el-form-item label="${comment}" prop="allInfo">-->
<!--          <el-input v-model="form.allInfo" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="图片" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'image'"
              :biz-type="'download'"
              :limit="1"
              style="margin-left: 20px"
              table-type="5"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="原文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz001'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="5"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="译文文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz002'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="5"
            ></FileUpload>
          </div>
        </el-form-item>

      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="精翻文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz003'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="5"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listExamplewar, getExamplewar, delExamplewar, addExamplewar, updateExamplewar } from "@/api/business/examplewar";
import { guid } from '@/utils/utils'
import FileUpload from '@/components/fileUpload_neww.vue'
import Pictures from '@/components/Pictures'
export default {
  name: "Examplewar",
  components: { Pictures,FileUpload },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 战例数据表格数据
      examplewarList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        chineseName: null,
        chineseNameKg: null,
        englishName: null,
        englishNameKg: null,
        initiator: null,
        target: null,
        targetKg: null,
        startTime: null,
        startTimeKg: null,
        endTime: null,
        endTimeKg: null,
        objective: null,
        industry: null,
        industryKg: null,
        objectOfAttack: null,
        content: null,
        weaponTool: null,
        weaponToolKg: null,
        effect: null,
        keywords: null,
        caseKeywords: null,
        allInfo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        chineseName: [
          { required: true, message: "中文名称不能为空", trigger: "blur" }
        ],
        chineseNameKg: [
          { required: true, message: "中文名称-图谱不能为空", trigger: "blur" }
        ],
        englishName: [
          { required: true, message: "英文名称不能为空", trigger: "blur" }
        ],
        englishNameKg: [
          { required: true, message: "英文名称-图谱不能为空", trigger: "blur" }
        ],
        initiator: [
          { required: true, message: "发动方不能为空", trigger: "blur" }
        ],
        target: [
          { required: true, message: "攻击目标不能为空", trigger: "blur" }
        ],
        targetKg: [
          { required: true, message: "攻击目标-图谱不能为空", trigger: "blur" }
        ],
        startTime: [
          { required: true, message: "起始时间不能为空", trigger: "blur" }
        ],
        startTimeKg: [
          { required: true, message: "起始时间-图谱不能为空", trigger: "blur" }
        ],
        endTime: [
          { required: true, message: "结束时间不能为空", trigger: "blur" }
        ],
        endTimeKg: [
          { required: true, message: "结束时间-图谱不能为空", trigger: "blur" }
        ],
        objective: [
          { required: true, message: "作战目的不能为空", trigger: "blur" }
        ],
        industry: [
          { required: true, message: "所属行业不能为空", trigger: "blur" }
        ],
        industryKg: [
          { required: true, message: "所属行业-图谱不能为空", trigger: "blur" }
        ],
        objectOfAttack: [
          { required: true, message: "攻击对象不能为空", trigger: "blur" }
        ],
        content: [
          { required: true, message: "作战内容不能为空", trigger: "blur" }
        ],
        weaponTool: [
          { required: true, message: "作战工具/武器不能为空", trigger: "blur" }
        ],
        weaponToolKg: [
          { required: true, message: "作战工具/武器-图谱不能为空", trigger: "blur" }
        ],
        effect: [
          { required: true, message: "作战效果不能为空", trigger: "blur" }
        ],
        keywords: [
          { required: true, message: "相关报道不能为空", trigger: "blur" }
        ],
        caseKeywords: [
          { required: true, message: "战例关键词不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询战例数据列表 */
    getList() {
      this.loading = true;
      listExamplewar(this.queryParams).then(response => {
        this.examplewarList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        chineseName: null,
        chineseNameKg: null,
        englishName: null,
        englishNameKg: null,
        initiator: null,
        target: null,
        targetKg: null,
        startTime: null,
        startTimeKg: null,
        endTime: null,
        endTimeKg: null,
        objective: null,
        industry: null,
        industryKg: null,
        objectOfAttack: null,
        content: null,
        weaponTool: null,
        weaponToolKg: null,
        effect: null,
        keywords: null,
        caseKeywords: null,
        allInfo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加战例数据";
      let mizId = guid().replace(/-/g, '');
      this.form.id = mizId
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getExamplewar(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改战例数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateExamplewar(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addExamplewar(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除战例数据编号为"' + ids + '"的数据项？').then(function() {
        return delExamplewar(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/examplewar/export', {
        ...this.queryParams
      }, `examplewar_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
